package org.other.testPk;

import java.util.concurrent.*;

/**
 * @Author yu
 * @Date 2022/7/9
 */
public class Demo5 {

    public static void main(String[] args) {

        int threadCount = 500;
        CountDownLatch countDownLatch = new CountDownLatch(threadCount);

        ExecutorService pool = Executors.newFixedThreadPool(threadCount);

        for (int i = 0; i < threadCount; i++) {
            pool.execute(() -> {
                try {
                    System.out.println(Thread.currentThread().getName() + " do something!");
                } catch (Exception e) {
                    System.out.println("Exception: do something exception");
                } finally {
                    //该线程执行完毕-1
                    countDownLatch.countDown();
                }
            });
        }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main thread do something-1");
        System.out.println("main thread do something-2");
        pool.shutdown();

    }

}
